package com.util;

import lombok.extern.slf4j.Slf4j;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.regex.Pattern;

@Slf4j
public class PhoneValidator implements ConstraintValidator<Phone,String> {
 
    @Override
    public void initialize(Phone constraintAnnotation) {
        ConstraintValidator.super.initialize(constraintAnnotation);
    }
 
    @Override
    public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
        if(value == null || "".equals(value)) {
            return false;
        }
        if(value.charAt(0) !='1'){
            return false;
        }
        return Pattern.compile("^1\\d{10}$").matcher(value).matches();
    }
}